//package test2;
//
//
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import javax.servlet.http.HttpServletResponse;
//import org.springframework.core.io.InputStreamResource;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//
///**
// * @author sunkai
// * @date 2023/3/16 9:38
// */
//@Controller
//@RequestMapping("/pdf")
//public class PdfController {
//
//    @GetMapping("/{filename}")
//    public ResponseEntity<InputStreamResource> downloadPdfFile(@PathVariable String filename, HttpServletResponse response) throws IOException {
//
//        //获取文件路径
//        String filePath = "/path/to/pdf/files/" + filename;
//
//        //创建文件对象
//        File file = new File(filePath);
//
//        //检查文件是否存在
//        if (!file.exists()) {
//            response.sendError(HttpStatus.NOT_FOUND.value(), "File not found");
//            return null;
//        }
//
//        //创建文件输入流
//        FileInputStream inputStream = new FileInputStream(file);
//
//        //设置响应头
//        HttpHeaders headers = new HttpHeaders();
//        headers.add("Content-Disposition", "attachment; filename=" + file.getName());
//        headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
//        headers.add("Pragma", "no-cache");
//        headers.add("Expires", "0");
//
//        //创建响应实体
//        ResponseEntity<InputStreamResource> responseEntity = ResponseEntity
//                .ok()
//                .headers(headers)
//                .contentLength(file.length())
//                .contentType(MediaType.parseMediaType("application/pdf"))
//                .body(new InputStreamResource(inputStream));
//
//        return responseEntity;
//    }
//}
//
